#include<iostream>
#include<string>
using namespace std;

/*可变长数组：模板+动态内存分配
  vector类内的函数可以实现可变长数组的功能
*/

/*
class vector{};

//演绎vector类的部分功能
template<typename T>
class Array{
	int total; //数组长度
	int _size; //元素个数  size <= total
	T *pdata; //指向数组的指针
public:
	Array(int t){
		total = t;
		_size = 0;
		pdata = new T[total];
	}
	
	void add(T num){
		if(_size < total){
			pdata[_size] = num;
			_size++;
		}
		else{
			total = total * 2; //扩充数组容量
			T *temp = new T[total]; //申请新空间
			for(int i = 0; i < _size; i++)
				temp[i] = pdata[i]; //将pdata的元素赋予temp
			temp[_size] = num; //将数值赋给temp
			_size++;
			delete []pdata; //收回pdata数组的空间(因为其能存放的元素个数小于输入的数组元素个数)
			pdata = temp; //将temp的元素赋给pdata
		}
	}
	
	void show(){
		for(int i = 0; i < _size; i++)
			cout << pdata[i] << "  ";
	}
	
	~Array(){
		delete []pdata;
		pdata = NULL;
	}
};

int main()
{
	Array<double> a(3);
	a.add(3.5); a.add(2.6); a.add(4.7); //total = 3
	a.add(5.8); a.add(1.9); a.add(8.5); //total = 6
	a.add(2.5); a.add(7.4); a.add(3.4); //total = 12
	a.show();
	
	return 0;
}
*/

/*模板+运算符重载*/

/*class stu{
	string name;
	double score;
public:
	stu(string n, double s){
		name = n;
		score = s;
	}
	bool operator>(int c){return score >90;}
	bool operator>(stu s){return score > s.score;}
};

template<typename T, typename G>
bool compare(T t, G g)
{
	return t > g;
	//s1 > 90;  s1.operator>(90)
	//s1 > s2;  s1.operator>(s2)
}

int main(){
	cout << compare(2, 3.5) << endl;
	cout << compare(3.4, 8) << endl;
	
	stu s1("zhangsan", 74);
	stu s2("lisi", 88);
	cout << compare(s1, 90); // T --> stu; G --> int
	cout << compare(s1, s2); // T --> stu; G --> stu
	
	return 0;
}*/
